using Admin2025.Application.Events;
using MediatR;
using Microsoft.Extensions.Logging;

namespace Admin2025.Application.EventHandlers;

//用户删除事件处理器 - 记录审计日志
public class UserDeletedAuditHandler : INotificationHandler<UserDeleteNotification>
{
    private readonly ILogger<UserDeletedAuditHandler> _logger;
    public UserDeletedAuditHandler(ILogger<UserDeletedAuditHandler> logger)
    {
        _logger = logger;
    }

    public async Task Handle(UserDeleteNotification notification, CancellationToken cancellationToken)
    {
        var userEvent = notification.UserDeletedEvent;

        _logger.LogInformation("用户创建审计：事件ID={Event},用户ID={UserId},用户名={Username}，删除者={DeletedBy}，创建时间={OccurredOn}",
            userEvent.EventId,
            userEvent.UserId,
            userEvent.Username,
            userEvent.DeletedBy,
            userEvent.OccurredOn
        );
        //这里可以记录到审计日志表
        await Task.CompletedTask;
    }
}